package com.group4.edu.controller;


import com.group4.edu.entity.Video;
import com.group4.edu.service.VideoService;
import com.study.util.LogUtils;
import com.study.util.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author cloud
 * @since 2022-03-10
 */
@RestController
@RequestMapping("/edu/video")
@Slf4j
@CrossOrigin
@Api(description = "小节管理")
public class VideoController {

    @Autowired
    private VideoService videoService;

    @ApiOperation(value = "添加小节")
    @PostMapping("save-video-info")
    public ResponseResult addVideo(@RequestBody Video video){
        LogUtils.info(log,"添加小节",video);
        videoService.save(video);
        return ResponseResult.SUCCESS;
    }

    @ApiOperation(value = "通过id查小节")
    @GetMapping("video-info/{id}")
    public ResponseResult getVideo(@PathVariable String id){
        LogUtils.info(log,"通过id查小节",id);
        Video video = videoService.getById(id);
        return new ResponseResult(video);
    }

    @ApiOperation(value = "通过id改小节")
    @PutMapping("update-video-info/{id}")
    public ResponseResult updateVideo(@RequestBody Video video,
                                      @PathVariable String id){
        LogUtils.info(log,"通过id改小节",video);
        videoService.updateById(video);
        return new ResponseResult(video);
    }

    @ApiOperation(value = "通过id删除小节")
    @DeleteMapping("{id}")
    public ResponseResult deleteVideo(@PathVariable String id){
        LogUtils.info(log,"通过id删除小节",id);
        videoService.removeById(id);
        return ResponseResult.SUCCESS;
    }

}

